package org.example.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author liyishan
 * @date 2024/3/8 17:55
 * @apiNote
 */
@RestController
public class PredictionController {

    @GetMapping("/predict")
    public float predict(@RequestParam float x)throws Exception{
        float m = Float.parseFloat(new String(Files.readAllBytes(Paths.get("linear_model","m.txt"))));
        float b = Float.parseFloat(new String(Files.readAllBytes(Paths.get("linear_model", "b.txt"))));
        return m*x+b;
    }
}
